package machine.statistics.aop;

import machine.bean.Msg;
import machine.utils.GroupUtils;
import machine.utils.StatisticalUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author zhanghui145
 * @date 2021/12/26 14:21
 * @since 1.0.0
 */
@Aspect
@Component
public class GroupMsgCountAop {
    @Pointcut("execution (* machine.send.service.*.reply(..))")
    public void mapper() {
        // 切面
    }

    @Before("mapper()")
    public void countMsg(JoinPoint joinPoint){
        Object object = joinPoint.getArgs()[0];
        Msg msg = (Msg)object;
        if (msg != null && GroupUtils.friendGroup().equals(msg.getGroup_id())) {
            StatisticalUtil.add(String.valueOf(msg.getSender().getUser_id()),
                    msg.getSender().getNickname());
        }
    }
}
